﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Drawing;

namespace CustSign
{
    class FontBase
    {
        Int32 cRedValue, cGreenValue, cBlueValue, cintFontSize;
        String cstrFontName, cstrWelcome, cstrFontStyle;
        FontStyle cfsFontStyle;
        Font cfFont;
        Color ccColor;

        internal Int32 RedValue
        {
            get
            {
                return cRedValue;
            }
            set
            {
                cRedValue = value;
            }
        }

        internal Int32 GreenValue
        {
            get
            {
                return cGreenValue;
            }
            set
            {
                cGreenValue = value;
            }
        }

        internal Int32 BlueValue
        {
            get
            {
                return cBlueValue;
            }
            set
            {
                cBlueValue = value;
            }
        }

        internal Int32 intFontSize
        {
            get
            {
                return cintFontSize;
            }
            set
            {
                cintFontSize = value;
            }
        }

        internal String strFontName
        {
            get
            {
                return cstrFontName;
            }
            set
            {
                cstrFontName = value;
            }
        }

        internal String strWelcome
        {
            get
            {
                return cstrWelcome;
            }
            set
            {
                cstrWelcome = value;
            }
        }

        internal String strFontStyle
        {
            get
            {
                return cstrFontStyle;
            }
            set
            {
                cstrFontStyle = value;
            }
        }

        internal FontStyle fsFontStyle
        {
            get
            {
                return cfsFontStyle;
            }
        }

        internal Font fFont
        {
            get
            {
                return cfFont;
            }
        }

        internal Color cColor
        {
            get
            {
                return ccColor;
            }
        }

        internal void FontGet()
        {
            OleDbConnection Conn = new OleDbConnection(Properties.Settings.Default.strOleConn);

            OleDbCommand Comm = Conn.CreateCommand();
            OleDbDataReader CustRead;
            Conn.Open();

            Comm.CommandText = "SELECT TOP 1 CWelCome, RedValue, GreenValue, BlueValue, FontName, FontStyle, FontSize FROM TOption";
            CustRead = Comm.ExecuteReader();

            while (CustRead.Read())
            {
                cRedValue = (Int32)CustRead["RedValue"];
                cGreenValue = (Int32)CustRead["GreenValue"];
                cBlueValue = (Int32)CustRead["BlueValue"];
                cstrFontName = (String)CustRead["FontName"];
                cstrFontStyle = (String)CustRead["FontStyle"];
                cintFontSize = (Int32)CustRead["FontSize"];
                cstrWelcome = (String)CustRead["CWelCome"];
            }
            CustRead.Close();

            CustRead.Dispose();
            Comm.Dispose();
            Conn.Close();
            Conn.Dispose();

            cfsFontStyle = fsFontStyleGet(cstrFontStyle);
            cfFont = new Font(cstrFontName, cintFontSize, cfsFontStyle);
            ccColor = Color.FromArgb(cRedValue, cGreenValue, cBlueValue);
        }

        internal void FontSave()
        {
            OleDbConnection Conn = new OleDbConnection(Properties.Settings.Default.strOleConn);

            OleDbCommand Comm = Conn.CreateCommand();

            Conn.Open();

            Comm.CommandText = "UPDATE TOption SET CWelCome = '" + cstrWelcome + "', RedValue = " + cRedValue.ToString() + ", GreenValue = " + cGreenValue.ToString() + ", BlueValue = " + cBlueValue.ToString() + ", FontName = '" + cstrFontName + "', FontStyle = '" + cstrFontStyle + "', FontSize = " + cintFontSize.ToString() + " WHERE (ID = 1)";
            Comm.ExecuteNonQuery();

            Comm.Dispose();
            Conn.Close();
            Conn.Dispose();
        }

        internal FontStyle fsFontStyleGet(String strFontStyleIn)
        {
            if (strFontStyleIn == "Bold")
            {
                return FontStyle.Bold;
            }
            else if (strFontStyleIn == "Italic")
            {
                return FontStyle.Italic;
            }
            else if (strFontStyleIn == "Strikeout")
            {
                return FontStyle.Strikeout;
            }
            else if (strFontStyleIn == "Underline")
            {
                return FontStyle.Underline;
            }
            else
            {
                return FontStyle.Regular;
            }
        }
    }
}
